package com.asnike.util{
	import flash.display.BitmapData;
	import flash.display.Sprite;
	import flash.geom.Point;
	import flash.geom.Rectangle;
	
	public class ASImageCropper extends Sprite{
		
		static public function getImages( $bitmapData:BitmapData, $xmlData:XML ):Array{
			var i:int, j:int, results:Array;
			
			results = [];
			for( i = 0, j = $xmlData.image.length() ; i < j ; ++i ){
				results[results.length] = getImage( $bitmapData, $xmlData.image[i] );
			}
			
			return results;
		}
		static private function getImage( $bitmapData:BitmapData, $xmlData:XML ):BitmapData{
			var x:Number, y:Number, width:Number, height:Number, rect:Rectangle, result:BitmapData;
			
			rect = getRectFromXML( $xmlData );
			result = new BitmapData( rect.width, rect.height, true );
			result.copyPixels( $bitmapData, rect, new Point ); 
			
			return result;
		}
		static private function getRectFromXML( $xml:XML ):Rectangle{
			return new Rectangle( Number( $xml.@x ), Number( $xml.@y ), Number( $xml.@width ), Number( $xml.@height ) );
		}
		
		public function ASImageCropper(){
		}
	}
}